package net.sunofbeaches.dao;

import net.sunofbeaches.pojo.Label;
import net.sunofbeaches.pojo.Setting;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

@Transactional
public interface LabelDao extends JpaRepository<Label,String>, JpaSpecificationExecutor<Label> {
    @Modifying
    int deleteOneById(String id);

    @Modifying
    @Query(value = "DELETE from `tb_labels` where id = ?",nativeQuery = true)
    int customDeleteLabelById(String id);

    /**
     * 根据ID查找一个标签
     *
     * @param id
     * @return
     */
    Label findOneById(String id);

    Label findOneByName(String name);

    @Modifying
    @Query(nativeQuery = true,value = "UPDATE `tb_labels` SET `count` = `count` + 1 WHERE `name` = ?")
    int updateCountByName(String label);
}
